<?php

class Application_Model_Email extends Application_Model_DomainObject {

	protected  $_id;

	protected $_recipients;

	protected $_userid;

	protected $_title;

	protected $_content;

	protected $_status;

        
	/**
	 * add by wuzw
	 */
	protected static function getDb(){
		return new Application_Model_DbTable_Email();
	}
        /**
         * 获取邮件列表
         * @param type $nikename 用户呢称
         * @param type $count
         * @param type $offset
         * @return type
         */
	public static function getselemail($nikename,$count,$offset)
        {
            $where = array();
            $and = '';
            if($nikename != ''){
                $result = Application_Model_User::getbynikename($nikename);
                if($result){
                    $where[$and.' userId = '] = $result->id;
                    $and = ' and ';
                }else{
                    return array();
                }
            }
            return Application_Model_Email::getDao()->queryPage($where, ' id desc', $count, $offset);
        }
        
        
        public static function sendMail($userid,$email,$title,$content)
        {
                $mailItem = new Application_Model_Email();
                $mailItem->recipients = $email;
                $mailItem->userid = $userid;
                $mailItem->title = $title;
                $mailItem->content = $content;
                $mailItem->status = 0;
                $mailItem->save();
        }

                public function getuserinfo()
        {
            return Application_Model_User::load($this->_userid);
        }
}